﻿@{
    ViewBag.Title = "新增管理员";
}
<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="password2" name="password2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="phoneNum" name="phoneNum">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="@Html.Raw("@")" name="email" id="email">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>城市：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("cityId", new SelectList(ViewBag.cities, "Id", "Name"), new { @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色：</label>
            <div class="formControls col-xs-8 col-sm-9 check-box-list">
                @foreach (var role in ViewBag.Roles)
                {
                    <label for="role_@role.Id" class="col-xs-4">
                        <input type="checkbox" class="checkbox" id="role_@role.Id" value="@role.Id" name="adminRoles[]">@role.Name
                    </label>
                }
                <label id="adminRoles[]-error" class="col-xs-4 error" for="adminRoles[]">未设置用户角色</label>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section FooterScript
{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#form-admin-add").validate({
                rules: {
                    name: {
                        required: true,
                        minlength: 4,
                        maxlength: 16,
                        remote: '/WebAdmin/AdminUser/Exist'
                    },
                    password: {
                        required: true,
                    },
                    password2: {
                        required: true,
                        equalTo: "#password"
                    },
                    //"adminRoles[]": {
                    //    required: true
                    //}
                    //phoneNum: {
                    //	required:true,
                    //	isPhone:true,
                    //},
                    //email: {
                    //	required:true,
                    //	email:true,
                    //}
                },
                messages: {
                    name: {
                        remote: '已存在，请更换'
                    }
                    //"adminRoles[]": {
                    //    required: '未设置用户角色'
                    //}
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'POST',
                        url: "/WebAdmin/AdminUser/Add",
                        success: function (res) {
                            if (res.status == "ok") {
                                parent.layer.msg('新增成功!', { icon: 1, time: 1000 }, function () {
                                    parent.$('.btn-refresh').click();
                                    //parent.location.reload(); //刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            } else if (res.status == "redirect") {
                                location.href = res.data;
                            } else if (res.status == "error") {
                                layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                            } else {
                                layer.msg("新增失败", { icon: 2, time: 1000 });
                            }

                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('网络出错!', { icon: 2, time: 1000 });
                        }
                    });
                }
            });
        });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
}

